<?php


namespace App\Controller;

use App\Annotation\TestAnnotation;
use Hyperf\Di\Annotation\AnnotationCollector;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Middleware\TestMiddleware;

/**
 * @Controller()
 * @TestAnnotation(zjs="321")
 */
class TestController extends AbstractController
{
    private $cc = 1;

    /**
     * @RequestMapping(methods={"GET"}, path="get")
     */
    public function get()
    {
        return $this->response->json([
            'code'        => 200,
            'msg'         => 'This Get Request',
            'date'        => date('Y-m-d H:i:s'),
            'annotations' => AnnotationCollector::getClassesByAnnotation(TestAnnotation::class),
        ]);
    }

    /**
     * @PostMapping(path="/post")
     */
    public function post()
    {
        return $this->response->json([
            'code' => 200,
            'msg'  => 'This Post Request',
            'date' => date('Y-m-d H:i:s'),
        ]);
    }


    /**
     * @GetMapping(path="/middleware/test")
     * @Middleware(TestMiddleware::class)
     */
    public function testMiddleware()
    {
        return $this->response->json([
            'info' => 123
        ]);
    }
}